package fr.isis;

import javax.jdo.PersistenceManager;


public class DAO {
	
	public UserData findUserByKey(String mail, PersistenceManager pm){
		
		UserData userData = null;
				
		try{
			userData = pm.getObjectById(UserData.class, mail);
		}catch(Exception e){
			
		}
		
		return userData;
	}
	
	public boolean createUserRecord(String mail, PersistenceManager pm){
		
		boolean success = false;
		UserData record = new UserData(mail);
		try{
			pm.makePersistent(record);
			success = true;
		}catch(Exception e){
			
		}
		
		return success;
	}
	
	public void incrementer(String mail, PersistenceManager pm){
		DAO dao = new DAO();
		UserData userData = dao.findUserByKey(mail, pm);
		
		if(userData!=null)
			userData.incrementNumberOfConnections();
		pm.makePersistent(userData);
		// pm.close();
	}
}
